package com.topInterview;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @Author: huangzhigao
 * @Date: 2022/2/25 20:51
 */
public class leecode297_serial {
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }


    // Encodes a tree to a single string.
    public String serialize(TreeNode root) {
        if (root == null) {
            return null;
        }
        List<String> list = new ArrayList<>();

        Queue<TreeNode> queue = new LinkedList<>();
        queue.add(root);
        list.add(String.valueOf(root.val));
        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();

            if (node.left != null) {
                queue.add(node.left);
            } else {
                list.add(null);
            }
            if (node.right != null) {
                queue.add(node.right);
            } else {
                list.add(null);
            }
        }

        return null;


    }

    // Decodes your encoded data to tree.
//    public TreeNode deserialize(String data) {
//
//    }
}
